package com.net.ip01;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;

/**
 * 在InetAddressDemo基础下，封装了端口
 *
 * @author jiangbang
 * @date 2016/7/21
 */
public class InetSocketDemo02 {

    public static void main(String[] args) throws UnknownHostException {
        InetSocketAddress address = new InetSocketAddress("127.0.0.1",80);
        address = new InetSocketAddress(InetAddress.getByName("127.0.0.1"),80);
        System.out.println(address.getHostName());//输出计算机名
        System.out.println(address.getPort());//输出计算机名
        InetAddress addr = address.getAddress();
        System.out.println(addr.getHostAddress());//返回：192.168.1.100
        System.out.println(addr.getHostName());//输出计算机名

    }
}

